Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doctest failures for Python 3.10+ on AttributeError messages #56

Merged
merged 1 commit into from
Jan 31, 2024

Conversation

sadielbartholomew
Copy link
Member

@sadielbartholomew sadielbartholomew commented Jan 31, 2024

Quick one to fix some doctest failures for a full tests suite pass across supported Python 3.X versions. Notably there were a few failures due to the feature introduced in Python 3.10 which adds "Did you mean ..." suggestions to some error messages, such that Python 3.8 gives a shorter AttributeError and in the affected cases:

Python 3.8.17 | packaged by conda-forge | (default, Jun 16 2023, 07:06:00) 
[GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cfunits
>>> cfunits.Units('days since 2000-1-1').calendar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/slb93/git-repos/cfunits/cfunits/units.py", line 1775, in calendar
    raise AttributeError(
AttributeError: Units has no attribute 'calendar'

whereas e.g. Python 3.12 will show the extended message:

Python 3.12.0 | packaged by conda-forge | (main, Oct  3 2023, 08:43:22) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cfunits
>>> cfunits.Units('days since 2000-1-1').calendar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/slb93/git-repos/cfunits/cfunits/units.py", line 1775, in calendar
    raise AttributeError(
AttributeError: Units has no attribute 'calendar'. Did you mean: '_calendar'?

The ellipsis ... marker indicates to doctest any or no text at that location is acceptable and will ensure the tests pass for both message versions, and users can interpret it in the natural way as 'there may be further text after this', so it works for both machine and human.

@sadielbartholomew sadielbartholomew added documentation Improvements or additions to documentation testing Issues related to units tests and their coverage labels Jan 31, 2024
@sadielbartholomew sadielbartholomew self-assigned this Jan 31, 2024
@sadielbartholomew
Copy link
Member Author

Hmm, noticing now that there are plenty of setup issues with the CI workflows, very likely due to it being out-of-date. I'll try to address those shortly. As for this PR, the results aren't useful so I'll merge straight away.

Trivial change so no review requested/required.

@sadielbartholomew sadielbartholomew changed the title Fix doctest failures for Python 3.10+ due to AttributeError messages Fix doctest failures for Python 3.10+ on AttributeError messages Jan 31, 2024
@sadielbartholomew sadielbartholomew merged commit 4326299 into NCAS-CMS:main Jan 31, 2024
26 of 92 checks passed
@sadielbartholomew sadielbartholomew deleted the doctesting branch January 31, 2024 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation testing Issues related to units tests and their coverage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant